package www.wen.com.common.lib.util

import android.annotation.SuppressLint
import java.text.SimpleDateFormat
import java.util.*

/**
 * @author WEN
 * @Description:
 * @date 2021/3/2 0:00
 */
object DateUtil {

    private lateinit var calendar: Calendar

    /**
     * 功能描述：返回日
     */
    fun getDay(millisecond: Long): Int {
        calendar = Calendar.getInstance()
        calendar.time = Date(millisecond)
        return calendar.get(Calendar.DAY_OF_MONTH)
    }

    /**
     * 功能描述：返回年
     */
    fun getYear(millisecond: Long): Int {
        calendar = Calendar.getInstance()
        calendar.time = Date(millisecond)
        return calendar.get(Calendar.YEAR)
    }

    /**
     * 功能描述：返回年
     */
    fun getMonth(millisecond: Long): Int {
        calendar = Calendar.getInstance()
        calendar.time = Date(millisecond)
        return calendar.get(Calendar.MONTH)
    }

    /**
     * 功能描述：返回英文月份
     */
    fun getMonthFormatEn(millisecond: Long): String {
        calendar = Calendar.getInstance()
        calendar.time = Date(millisecond)
        var month = ""
        when (calendar.get(Calendar.MONTH)) {
            0 -> month = "Jan"
            1 -> month = "Feb"
            2 -> month = "Mar"
            3 -> month = "Apr"
            4 -> month = "May"
            5 -> month = "Jun"
            6 -> month = "Jul"
            7 -> month = "Aug"
            8 -> month = "Sep"
            9 -> month = "Oct"
            10 -> month = "Nov"
            11 -> month = "Dec"
        }
        return month
    }

    /**
     * 功能描述：返回数字月份
     */
    fun getMonthNumber(millisecond: Long): Int {
        calendar = Calendar.getInstance()
        calendar.time = Date(millisecond)
        return calendar.get(Calendar.MONTH) + 1
    }

    fun format(timeStamp: Long, format: String = "yyyy-MM-dd HH:mm"): String {
        val simpleDateFormat = SimpleDateFormat(format)
        return simpleDateFormat.format(Date(timeStamp))
    }

    @SuppressLint("SimpleDateFormat")
    fun strToTimeStamp(timeStampStr: String, format: String = "yyyy-MM-dd HH:mm"):Long  {
        val simpleDateFormat =  SimpleDateFormat(format)
        val date = simpleDateFormat.parse(timeStampStr)
        return date!!.time
    }

}